package cn.wolfcode.luowowo.job;

import cn.wolfcode.luowowo.redis.IStrategyRedisVO;
import cn.wolfcode.luowowo.redis.vo.StrategyStatisVO;
import cn.wolfcode.luowowo.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * redis数据持久化
 */
//@Component//解开封印
public class RedisDataPersistenceJob {
    @Autowired
    private IStrategyRedisVO strategyRedisVO;
    @Autowired
    private IStrategyService strategyService;
    /**
     * redis中数据的持久化操作
     * 每隔20s刷新一次
     */
    @Scheduled(cron = "0/10 * * * * ? ")
    public void dataPersistence(){
        System.out.println("--------------redis持久化开始---------------");
        //先将Redis中的vo数据查出来
        List<StrategyStatisVO> vos = strategyRedisVO.searchRedisVo();
        //再遍历vo更新到数据库中
        for (StrategyStatisVO vo : vos) {
            strategyService.updateToDate(vo);
        }
        System.out.println("--------------redis持久化结束---------------");
    }
}